package com.zhu.dao;

import com.zhu.pojo.Classes;
import com.zhu.utils.JDBCUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ClassDao {
    private Connection connection;
    private PreparedStatement preparedStatement;
    private ResultSet resultSet;
    public List<Classes> getClasses() throws SQLException {
        ArrayList<Classes> classesList = new ArrayList<>();

        connection = JDBCUtil.getInstance().getConnection();
        preparedStatement = connection.prepareStatement("select * from classes");
        resultSet = preparedStatement.executeQuery();
        Classes classes ;
        while (resultSet.next()) {
            classes = new Classes();
            classes.setCid(resultSet.getInt("cid"));
            classes.setCname(resultSet.getString("cname"));
//            student.setCname(resultSet.getString("id"));
            classesList.add(classes);
        }
        return classesList;
    }
}
